<%@ page contentType ="text/html; charset=UTF-8"%>
<%@ page import="java.sql.*, java.util.*" %>
<jsp:include page="header.jsp"/>

<jsp:include page="aside_admin.jsp"/>

<body>

	 <article>

	 	
	 
 <%
String key=request.getParameter("Key");
String keyword=request.getParameter("keyword");
String pageNum = request.getParameter("pageNum");
if(pageNum == null)
{
	pageNum = "1";
}

int listSize = 10;
int currentPage = Integer.parseInt(pageNum);
int StartRow = currentPage * listSize - listSize;
int maxRow;

Class.forName("com.mysql.jdbc.Driver");

Connection conn = null;
PreparedStatement pstmt = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL="";
try{
	String jdbcDriver ="jdbc:mysql://192.168.0.120:3306/coffee?" +
			"useUnicode=true&characterEncoding=euckr";
String dbUser="root";
String dbPass="123456";

	
	conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPass);
	
	stmt = conn.createStatement();
	
	
	
	if(key==null || keyword==null){
	strSQL="select * from member order by num DESC";
	}else{
	strSQL="select count(*) From member where "+key+"like '%"+keyword+"%'";
}
	//rs = stmt.executeQuery(strSQL);
%>

이름:<input type=text size=10>&nbsp;&nbsp;
	 	생년월일:<input type=text size=10>&nbsp;&nbsp;
	 	전화번호:<input type=text size=10>&nbsp;&nbsp;
	 	<input type=button value=검색>&nbsp;&nbsp;
	 	<p>
	 		
<div id="list">


<table border="0" width="700" cellpadding="0" cellspacing="0">
<tr>
	<td><hr size="1" noshad></td>
</tr>		
</table>
<table border="0" cellspacing="1" cellpadding="2" width="700">
	<tr bgcolor="cccccc">
	<td><font size="2"><center><b>NUM</b></center></font></td>
	<td><font size="2"><center><b>이름</b></center></font></td>
	<td><font size="2"><center><b>전화번호</b></center></font></td>
	<td><font size="2"><center><b>생년월일</b></center></font></td>
	<td><font size="2"><center><b>이메일</b></center></font></td>
	<td><font size="2"><center><b>주소</b></center></font></td>
	<td><font size="2"><center><b>가입날짜</b></center></font></td>
	<td><font size="2"><center><b>포인트</b></center></font></td>
	
	</tr>

<%
strSQL = "select count(*) from member";
rs = stmt.executeQuery(strSQL);
rs.next();
maxRow = rs.getInt("count(*)");
//System.out.println(maxRow);

strSQL = "select * from member order by num desc limit " + StartRow + ", " + listSize;
rs = stmt.executeQuery(strSQL);

for(int i=0; i<listSize; i++){
if(rs.next()){
	int num = rs.getInt("num");
	String name = rs.getString("name");
	String email = rs.getString("email");
	String tel = rs.getString("tel");
	String address = rs.getString("address");
	String regdate = rs.getString("reg_date");
	String birth = rs.getString("birth");
	int point = rs.getInt("point");
	
%>
<tr bgcolor="ededed">
	<td align="center"><font size="2" color="black">
		<a href=member_output.jsp?num=<%=num %>><%=num%></font></td>
	<td align="center"><font size="2" color="black">
	<a href=member_output.jsp?num=<%=num %>>
		<%=name %></font></td>
	<td align="center"><font size="2" color="black"><%=tel %></font></td>
	<td align="center"><font size="2"><%=birth %></font></td>
	<td align="center"><font size="2" color="black"><%=email %></font></td>
	<td align="center"><font size="2" color="black"><%=address %></font></td>
	<td align="center"><font size="2" color="black"><%=regdate %></font></td>
	
	<td align="center"><font size="2"><%=point %></font></td>

<%
	}
}
%>
</table>
<table border="0" width="700" cellpadding="0" cellspacing="0">
<tr>
	<td><hr size="1" noshade>
	</td>
</tr>
</table>


<%

int setPage=1;
int lastPage=0;
lastPage = maxRow / listSize +1;


while(setPage <= lastPage)
{
%>
	<a href="listboard.jsp?pageNum=<%=setPage %>">[<%=setPage %>]
	</a>
<%	
	setPage = setPage + 1;
}

}catch(SQLException ex){
	out.println(ex.getMessage());
}finally{
	if(rs != null) try{rs.close();} catch(SQLException ex){}
	if(stmt != null) try{stmt.close();} catch(SQLException ex){}
	if(conn != null) try{conn.close();} catch(SQLException ex){}
}

%>

</body>
</article>
</div>
<jsp:include page="footer.jsp"/>